package com.med.service;

import com.med.entity.MedicineDO;
import com.med.mapper.MedicineMapper;
import com.med.service.IMedicineService;
import com.med.vo.MedicineVO;
import com.ruoyi.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MedicineServiceImpl implements IMedicineService {

    @Autowired
    private MedicineMapper medicineMapper;

    @Override
    public R<String> add(MedicineVO medicineVO) {
        Integer add = medicineMapper.add(medicineVO);
        if (add != 0) {
            return R.ok("添加药品成功");
        }
        return R.ok("添加药品失败");
    }

    @Override
    public R<List<MedicineDO>> queryAllMedicine(MedicineVO medicineVO) {
        List<MedicineDO> medicineDOS = medicineMapper.queryMedicineByVO(medicineVO);

        return R.ok(medicineDOS);
    }

    @Override
    public R<String> deleteMedicineById(Integer medicineId) {
        Integer i = medicineMapper.deleteMedicine(medicineId);
        if (i!=0){
            return R.ok("删除成功");
        }
        return R.ok("删除失败");
    }

    @Override
    public R<String> updateMedicineByVO(MedicineVO medicineVO) {
        Integer i = medicineMapper.updateMedicine(medicineVO);
        if (i!=0){
            return R.ok("删除成功");
        }
        return R.ok("删除失败");
    }


}
